import { defineStore } from "pinia";
import { UserState } from "@/stores/interface";
import piniaPersistConfig from "@/stores/helper/persist";
import { getUserInfoApi } from "@/api/modules/login";

export const useUserStore = defineStore({
  id: "geeker-user",
  state: (): UserState => ({
    token: "",
    userInfo: {},
    sysJobList: [],
    firstJobId: undefined,
    firstJobName: "",
    authMenuList: []
  }),
  getters: {},
  actions: {
    //设置token
    setToken(token: string) {
      this.token = token;
    },
    // 设置职位列表
    setSysJobList(sysJobList: UserState["sysJobList"]) {
      this.sysJobList = sysJobList;
    },
    // 设置职位当前职位id
    setFirstJobId(firstJobId: UserState["firstJobId"]) {
      this.firstJobId = firstJobId;
    },
    //设置职位当前职位名称
    setFirstJobName(firstJobName: UserState["firstJobName"]) {
      this.firstJobName = firstJobName;
    },
    // 设置用户信息
    setUserInfo(userInfo: UserState["userInfo"]) {
      this.userInfo = userInfo;
    },
    setAuthMenuList(authMenuList: UserState["authMenuList"]) {
      this.authMenuList = authMenuList;
    },
  },
  persist: piniaPersistConfig("geeker-user")
});
